Package com.fsf.news
Class ReflectionTestUtils
java.lang.Object
com.fsf.news.ReflectionTestUtils
Utility class for reflection operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldRetrieves a Field object from a class or its superclasses.static ObjectRetrieves the value of a static field from a class.static ObjectRetrieves the value of a field from an object.static voidSets the value of a static field in a class.static voidSets the value of a field in an object.
-
Constructor Details
-
ReflectionTestUtils
public ReflectionTestUtils()
-
-
Method Details
-
getField
Retrieves a Field object from a class or its superclasses.- Parameters:
clazz- The class to search for the fieldfieldName- The name of the field to retrieve- Returns:
- The Field object, or null if not found
-
getValue
Retrieves the value of a field from an object.- Parameters:
object- The object containing the fieldfieldName- The name of the field to retrieve- Returns:
- The value of the field
-
getValue
Retrieves the value of a static field from a class.- Parameters:
clazz- The class containing the fieldfieldName- The name of the field to retrieve- Returns:
- The value of the field
-
setValue
Sets the value of a field in an object.- Parameters:
object- The object containing the fieldfieldName- The name of the field to setvalue- The new value of the field
-
setValue
Sets the value of a static field in a class.- Parameters:
clazz- The class containing the fieldfieldName- The name of the field to setvalue- The new value of the field
-